$(function(){ 
	
	$("#nextBtn").on('click',initOrder);
	
	var today = new Date();

	var dtpicker = new mui.DtPicker({
	    type: "date",//设置日历初始视图模式 
	    beginDate: new Date(1900, 01, 01),//设置开始日期 
	    endDate: new Date(today.getFullYear(),today.getMonth(),today.getDate()-1),//设置结束日期 
	}) 

    $("#birthday").click(function(){
	    dtpicker.show(function(items) {
	    	$("#birthday").text(items.value).css("color","#333");
		   
		})  
    })
   
   //初始化订单
	function initOrder(){
		//真实姓名
	    var patientName=$("#patientName").val();
		if(patientName.trim()==""){
			mui.alert("请输入患者姓名!","提示");
			return;
		}
		//选择性别
		var sex=$("input[name='sex']:checked").val();
		//输入电话
		var answerMobile=$("#answerMobile").val();
		if(answerMobile.trim()==""){
			mui.alert("请输入电话!","提示");
			return;
		}
		if(!(/^1[345678]\d{9}$/.test(answerMobile))){ 
	    	mui.alert("您的电话号码有误,请重新输入","提示");  
	        return; 
	    }
		//出生日期
		var birthday=$("#birthday").text();
		if(birthday.trim()==""){
			mui.alert("请选择日期!","提示");
			return;
		}
		var now=new Date();
		var birthdaystr=birthday.split('-');
		if(now.getFullYear()<birthdaystr[0]){
			mui.alert('不可选大于当年',"提示");
			return false;
		}else if(now.getFullYear()==birthdaystr[0]){
			if(now.getMonth()+1<birthdaystr[1]){
			mui.alert('不可选等于当年,大于当月',"提示");
			return false;
			}else if(now.getMonth()+1==birthdaystr[1]){
				if(now.getDate()< birthdaystr[2]){
					mui.alert('不可选等于当年等于当月,而大于当天',"提示");
					return false;
				}			
			}	
		}
    	var  birthdaytime = birthday.replace(/-/g,"/");
	    var date = new Date(birthdaytime);
	    var datenow=new Date();
	    var age=datenow.getYear()-date.getYear();
	    if(age<0){
			mui.alert("您的输入有误,请重新输入","提示");
			return;
	    }
		
		//提交下一步
		var speedPhoneOrder={};
		speedPhoneOrder.answerMobile=answerMobile;
		speedPhoneOrder.patientName=patientName;
		speedPhoneOrder.patientSex=sex;
		speedPhoneOrder.birthday=birthday;
		var order_index_key="order_index";
	    sessionStorage.setItem(order_index_key,JSON.stringify(speedPhoneOrder));
	    location.href="rapidly-question.html?key="+order_index_key;
	}
	
	
	
    
    
    
	
   
   
   
   
   
   
   
   
   
   
});



